package com.xbongbong.pro.enums;

import com.xbongbong.paas.enums.FieldTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Author shian
 * @create 2020-03-14 15:40
 * @Description
 */
@Getter
public enum BusinessSearchEnum {

    /**
     * 工商查询匹配字段 参考文档：https://xbb.yuque.com/lfwuxq/vsf9sv/kwdupl
     */
    // 企业基本信息接口获取
    ENTERPRISE_NAME(1, "ENTNAME","enterpriseName", "企业名称", FieldTypeEnum.TEXT.getType(), 0, "Information"),

    HISTORY_NAME(2,"HISTORYNAME","historyName", "历史名称", FieldTypeEnum.TEXT.getType(), 0, "Information"),

    LEGAL_PERSON(3,"LEGALPERSON", "legalPerson", "法人/负责人", FieldTypeEnum.TEXT.getType(), 0, "Information"),

    LEGAL_PERSON_TYPE(4, "LEGALPERSONDESC", "legalPersonType", "法人名称类型", FieldTypeEnum.TEXT.getType(), 0, "Information"),

    ESTABLISH_DATE(5, "ESDATE","establishDate", "成立日期", FieldTypeEnum.DATETIME.getType(), 0, "Information"),

    REGISTER_NUMBER(6,"REGNO","registerNumber", "注册号", FieldTypeEnum.TEXT.getType(), 0, "Information"),

    UNIFORM_CREDIT_CODE(7,"UNCID","uniformCreditCode", "统一信用代码", FieldTypeEnum.TEXT.getType(), 0, "Information"),

    ENTERPRISE_TYPR(8,"ENTTYPE", "enterpriseType", "企业(机构)类型", FieldTypeEnum.TEXT.getType(), 0, "Information"),

    REGISTER_FUNDS(9, "REGCAP&&REGCAPCUR","registerFunds", "注册资金", FieldTypeEnum.TEXT.getType(), 0, "Information"),

    PROVINCE_CODE(10,"PROVINCE", "provinceCode", "省份代码", FieldTypeEnum.NUM.getType(), 0, "Information"),

    OPERATE_PERIOD_FROM(11,"OPFROM", "operatePeriod", "经营(驻在)期限自", FieldTypeEnum.DATETIME.getType(), 0, "Information"),

    OPERATE_PERIOD_TO(12,"OPTO", "operatePeriod", "经营(驻在)期限至", FieldTypeEnum.DATETIME.getType(), 0, "Information"),

    REGISTER_AUTHORITY(13,"REGORG", "registerAuthority", "登记机关", FieldTypeEnum.TEXT.getType(), 0, "Information"),

    APPROVAL_DATE(14,"APPRDATE", "approvalDate", "核准日期", FieldTypeEnum.DATETIME.getType(), 0, "Information"),

    LOGOUT_DATE(15,"REVOKEDATE","logoutDate", "注销日期", FieldTypeEnum.DATETIME.getType(), 0, "Information"),

    ENTERPRISE_STATUS(16,"ENTSTATUS","enterpriseStatus", "企业状态", FieldTypeEnum.TEXT.getType(), 0, "Information"),

//    INDUSTRY(17, "INDUSTRYPHY","industry","行业", FieldTypeEnum.TEXT.getType(), 0, "Information"),

    REGISTER_ADDRESS(18,"OPLOC","registerAddress", "注册地址", FieldTypeEnum.ADDRESS.getType(), 0, "Information"),

    MANAGE_SCOPE(19,"OPSCOPE","manageScope", "经营范围", FieldTypeEnum.TEXTAREA.getType(), 0, "Information"),

    MAIN_MEMBER(20,"PERSONS","mainMember", "主要成员", FieldTypeEnum.SUB_FORM.getType(), 0, "Information"),

    SHAREHOLDER(21,"BE_INVEST","shareholder", "股东", FieldTypeEnum.SUB_FORM.getType(), 0, "Information"),

    CLEARINGINFO(22,"CLEARINGINFO","clearingInfo", "清算信息", FieldTypeEnum.SUB_FORM.getType(), 0, "Information"),

    NAME(23,"NAME","name", "姓名", FieldTypeEnum.TEXT.getType(), 20, "Information"),

    POSITION(24,"POSITION","position", "职务", FieldTypeEnum.TEXT.getType(), 20, "Information"),

    SHAREHOLDER_NAME(25,"INV","shareholderName", "股东名", FieldTypeEnum.TEXT.getType(), 21, "Information"),

    SHAREHOLDER_TYPE(26,"INVTYPE","shareholderType", "股东类型", FieldTypeEnum.TEXT.getType(), 21, "Information"),

    CLEARING_GROUP_MEMBER_NAME(27,"liqMem","clearingMemberName", "清算组成员名称", FieldTypeEnum.TEXT.getType(), 22, "Information"),

    CLEARING_GROUP_MEMBER_TYPE(28,"ligpriSign","clearingMemberType", "清算组成员类型", FieldTypeEnum.TEXT.getType(), 22, "Information"),

    // 企业年报接口获取
    MOBILE(29,"tel","mobile", "联系电话", FieldTypeEnum.TEXT.getType(), 0, "Report"),

    EMAIL(30,"email","email", "邮箱", FieldTypeEnum.TEXT.getType(), 0, "Report"),
    ;

    /**
     * 字段id
     */
    private Integer code;

    /**
     * 字段变量名
     */
    private String attr;

    /**
     * 字段别名
     */
    private String alias;

    /**
     * 字段名称
     */
    private String attrName;

    /**
     * 字段类型
     */
    private Integer fieldType;

    /**
     * 字段是否是属于子表单中的，目前只有子表单中的字段parent不为0
     */
    private Integer parent;

    /**
     * 来源
     */
    private String source;

    BusinessSearchEnum(Integer code, String attr, String alias, String attrName, Integer fieldType, Integer parent, String source) {
        this.code = code;
        this.attr = attr;
        this.alias = alias;
        this.attrName = attrName;
        this.fieldType = fieldType;
        this.parent = parent;
        this.source = source;
    }

    public static List<BusinessSearchEnum> getByParentId(Integer code) {
        List<BusinessSearchEnum> list = new ArrayList<>(10);
        for (BusinessSearchEnum businessSearchEnum : values()) {
            if (Objects.equals(code, businessSearchEnum.getParent())) {
                list.add(businessSearchEnum);
            }
        }
        return list;
    }

    public static BusinessSearchEnum getByCode(Integer code) {
        for (BusinessSearchEnum businessSearchEnum : values()) {
            if (Objects.equals(code,businessSearchEnum.getCode())) {
                return businessSearchEnum;
            }
        }
        return null;
    }
}
